package com.lijing.SelectSort;

import java.util.Collection;

public class Selection {
    public static void sort(Comparable[] arr){
        for (int i = 0; i < arr.length -1; i++) {
            int minIndex = i;
            for (int j = i+1; j < arr.length; j++) {
                if (greater(arr[minIndex],arr[j])){
                    minIndex = j;
                }
            }
            exch(arr,i,minIndex);
        }
    }
    private static boolean greater(Comparable v, Comparable w){
        return v.compareTo(w)>0;
    }
    private static void exch(Comparable[] a, int i, int j){
        Comparable temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
